#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef enum {
    //黑桃，红桃，梅花，方片
    spades,hearts,clubs,diamonds
}Suit;

typedef enum {
    black,red
}Color;

typedef struct {
    Suit suit;
    Color color;
    int cardNo;
} Card,*pCard;

void swapCard(pCard card1,pCard card2){
    Card tmp;
    tmp.cardNo = card1->cardNo;
    tmp.color = card1->color;
    tmp.suit = card1->suit;

    card1->suit = card2->suit;
    card1->color = card2->color;
    card1->cardNo = card2->cardNo;

    card2->cardNo = tmp.cardNo;
    card2->color = tmp.color;
    card2->suit = tmp.suit;
}

void printCard(const Card card){
    if (card.cardNo <= 0){
        printf("Joker: ");
        if(card.color==black){
            printf("Black Joker\n");
        }
        if(card.color==red){
            printf("Red Joker\n");
        }
        return;
    }
    printf("Normal card, suit:");
    switch(card.suit){
        case spades:{
            printf("spades, ");break;
        }
        case hearts:{
            printf("hearts, ");break;
        }
        case clubs:{
            printf("clubs, ");break;
        }
        case diamonds:{
            printf("diamonds, ");break;
        }
    }
    printf("cardNo: ");
    if(card.cardNo <= 10){
        printf("%d",card.cardNo);
    }else{
        switch (card.cardNo) {
            case 11:{printf("Jack");break;}
            case 12:{printf("Queen");break;}
            case 13:{printf("King");break;}
        }
    }
    printf("\n");
}

int main() {
    pCard cards = calloc(54,sizeof(Card));
    for(int j=0; j<4; j++){
        for(int i=1;i<=13;i++){
            cards[j*13 + i-1].cardNo = i;
            cards[j*13 + i-1].color = j%2;
            cards[j*13 + i-1].suit = j;
        }
    }
    cards[52].cardNo = 0;
    cards[52].color = black;
    cards[53].cardNo = 0;
    cards[53].color = red;

    printf("澳门新葡京首家单机命令行赌场开业了！\n");
    printf("性感荷官，在线发牌！\n");
    srand(time(NULL));
    for(int i=0;i<54;i++){
        int a = rand()%54;
        int b = rand()%54;
        swapCard(&cards[a],&cards[b]);
    }

    for(int j=0;j<3;j++) {
        printf("玩家%d当前手牌为：\n",j);
        for (int i = 0; i < 17; i++) {
            printf("\t");
            printCard(cards[j*17 + i]);
        }
        printf("\n");
    }

    printf("当前底牌为：\n");
    for(int i=51;i<54;i++){
        printCard(cards[i]);
    }

    free(cards);
}
